const formidable = require('formidable')
const path = require('path')
const { Article } = require('../../model/article')
module.exports = (req, res) => {
    const form = new formidable.IncomingForm();
    form.uploadDir = path.join(__dirname, '../', '../', 'public', 'uploads')
    form.keepExtensions = true
    form.parse(req, async (err, fields, files) => {
        console.log(fields, 'sdads')
        await Article.create({
            title: fields.title[0],
            author: fields.author[0],
            publishDate: fields.publishDate[0],
            cover: files.cover[0].filepath.split("public")[1],
            content: fields.content[0]
        })
        res.redirect('/admin/article');
    })
}